package com.xiaoq.system.repository.impl;

import org.apache.commons.lang3.StringUtils;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.query.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xiaoq.system.entity.TermVerEntity;
import com.xiaoq.system.repository.ITermVerRepository;

@Repository
public class TermVerRepositoryImpl implements ITermVerRepository {
	
	@Autowired
	private Datastore datastore;
	
	private static final Logger LOG = LoggerFactory.getLogger(TermVerRepositoryImpl.class);

	@Override
	public TermVerEntity getNewTerVer(String termType) {
		Query<TermVerEntity> termVerQuery = datastore.find(TermVerEntity.class);
		TermVerEntity termVer = null;
		if(StringUtils.isNotEmpty(termType)){
			termVerQuery.field("termType").equal(termType).order("-pubTime");
			termVer = termVerQuery.get();
			
		}else{
			LOG.error("请传递具体终端类型！");
		}
		return termVer;
	}

}
